from odoo import api, fields, models


class SbOrderCache(models.Model):
    _name = 'sb.order.cache'

    apply_line_id = fields.Many2one('sale.change.apply.line', 'Change Apply Line')
    apply_id = fields.Many2one('sale.change.apply', related="apply_line_id.change_apply_id", string='Change Apply')
    sale_order_id = fields.Many2one('sale.order')
    target_order_id = fields.Many2one('sale.order')
    order_line_id = fields.Many2one('sale.order.line')
    product_id = fields.Many2one('product.product')
    origin_qty = fields.Float(string='Origin Qty')
    target_qty = fields.Float(string='Target Qty')
    origin_price = fields.Float(string='Origin Price', digits='Sale Unit Price')
    target_price = fields.Float(string='Target Price', digits='Sale Unit Price')
    origin_nre = fields.Float(string='Origin NRE')
    target_nre = fields.Float(string='Target NRE')
    origin_po = fields.Char(string='Origin PO')
    target_po = fields.Char(string='Target PO')
    origin_note = fields.Char(string='Origin Note')
    target_note = fields.Char(string='Target Note')
    fields.Many2one('customer.item.code', string="PN")
    origin_pn = fields.Many2one('customer.item.code', string='Origin PN')
    target_pn = fields.Many2one('customer.item.code', string='Target PN')
    target_pn_code = fields.Char(string='Target PN')
    origin_rev = fields.Char(string='Origin REV')
    target_rev = fields.Char(string='Target REV')
    # 不从此处发起修改计划交期，因此注释
    # origin_date = fields.Datetime(string='Origin Delivery Date')
    # target_date = fields.Datetime(string='Target Delivery Date')
    note = fields.Char(string='Notes')
    target_pn_desc = fields.Char(string='Target PN Desc')
    origin_pn_desc = fields.Char(string='Origin PN Desc')
    origin_qt = fields.Boolean('Origin QTA')
    target_qt = fields.Boolean('Target QTA')

    origin_materiel_status = fields.Selection([
        ('S', 'NPI'),
        ('P', 'MP'),
        ('T', 'Test'),
        ('Q', 'QTA+NPI'),
    ], string='Origin Product Status', tracking=True)

    target_materiel_status = fields.Selection([
        ('S', 'NPI'),
        ('P', 'MP'),
        ('T', 'Test'),
        ('Q', 'QTA+NPI'),
    ], string='Target Product Status', tracking=True)

    target_special_order_type = fields.Selection([
        ('eq_only', 'EQ only'),
        ('free_cost', 'Free cost'),
        ('in_stock', 'In stock'),
        ('prepare_materials', 'Prepare Materials'),
        ('nothing', 'Nothing')
    ], string="Target Special Order Type")
    origin_special_order_type = fields.Selection([
        ('eq_only', 'EQ only'),
        ('free_cost', 'Free cost'),
        ('in_stock', 'In stock'),
        ('wb', 'WB'),
        ('prepare_materials', 'Prepare Materials'),
        ('nothing', 'Nothing')
    ], string="Origin Special Order Type")
    origin_commitment_date = fields.Datetime(string='Origin Customer DD')
    target_commitment_date = fields.Datetime(string='Target Customer DD')
